// ***************************************************************************************
// Copyright (c) 2023-2025 Peng Cheng Laboratory
// Copyright (c) 2023-2025 Institute of Computing Technology, Chinese Academy of Sciences
// Copyright (c) 2023-2025 Beijing Institute of Open Source Chip
//
// iEDA is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
// http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
//
// See the Mulan PSL v2 for more details.
// ***************************************************************************************
#pragma once

// #include "TimingEval.hpp"
#include "contest_evaluation.h"
#include "contest_preprocess.h"
#include "contest_segment.h"
#include "route/make_route.h"

#include <map>
#include <string>

#include "gateSize/opt/path_net.h"
#include "HistogramCompression.h"
#include "QuadraticTDP.h"
#include "ToApi.hpp"
#include "contest_dm.h"
#include "contest_evaluation.h"
#include "DrivenStrengthCellMovement.h"
#include "AbuReduction.h"
#include "check.h"
#include "gateSize/GateSizing.h"

// #include <gperftools/profiler.h>

#include "PLAPI.hh"
/**
 * @File Name: contest_process.h
 * @Brief :
 * @Author : Yell (12112088@qq.com)
 * @Version : 1.0
 * @Creat Date : 2023-09-15
 *
 */
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace ieda_contest {
class ContestDataManager;
class ContestCoord;
class ContestNet;

class ContestProcess
{
 public:
  ContestProcess(ContestDataManager* data_manager);
  ~ContestProcess() = default;

  virtual bool doProcess() { return true; }
  void doTimingOpt();
  // void doTimingOpt1();
  void printWnsAndTns();

  static uint64_t _init_instance_area;
  static uint64_t _max_instance_area;

 private:
  ContestCoord getGCellCoord(const ContestCoord& coord);
  ContestNet makeContestNet(idb::IdbNet* idb_net, int net_id);
  void timingDrivenPlacement();
  void gateSizing();
  void timingDrivenOverlapReducation();
  void routing();
  void ripupAndReroute(MakeRoute* make_route);
  ContestDataManager* _data_manager = nullptr;
  QuadraticTDP* _qtdp;
  ieda::Stats _to_status;
};

}  // namespace ieda_contest